package cn.virens.common.boot.dubbo.filter.attachment;

import cn.virens.common.boot.dubbo.filter.AbstractDubboFilter;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;

import java.util.Map.Entry;

@Activate(group = CommonConstants.CONSUMER)
public class AttachmentConsumerFilter extends AbstractDubboFilter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        for (Entry<String, Object> e : AttachmentUtils.entrySet()) {
            invocation.setAttachment(e.getKey(), e.getValue());
        }

        return invoker.invoke(invocation);
    }
}
